package leetcode.力扣竞赛.第388场周赛;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * description:重新分装苹果
 *
 * @author 颜真明
 * @date 2024/3/10  19:56
 */
public class Solution100233 {
    public static void main(String[] args) {
        int[] num1 = new int[]{9,8,8,2,3,1,6};
        int[] num2 = new int[]{10,1,4,10,8,5};
        System.out.println(minimumBoxes(num1, num2));
    }
    public static int minimumBoxes(int[] apple, int[] capacity) {
        int weight = 0;
        int res = 0, sum = 0;
        for(int app : apple) {
            weight += app;
        }
        Arrays.sort(capacity);
        int[] cap = new int[capacity.length];
        for (int i = 0; i < capacity.length; i++) {
            cap[cap.length - i - 1] = capacity[i];
        }
        for(int i = 0; i < cap.length; i++) {
            sum += cap[i];
            res++;
            if (sum >= weight) {
                break;
            }
        }
        return res;
    }
}
